﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SzCourt.Logic.Common;
using KMFrame.Core;
using SzCourt.Logic.NBL;
using NBearLite;
using SzCourt.Logic.NBL.DBEntities;

namespace SzCourt.Logic.BLL
{
    public class UseStatistics : SzCourtLogic
    {
        /// <summary>
        /// 获取列表信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PageResult GetStatisticsList(PageParam condition, string siteCol, string deptName, string User,DateTime beginDate,DateTime endDate)
        {
            PageResult result = new PageResult();

            WhereClip where = WhereClip.All;

            if (!string.IsNullOrEmpty(siteCol))
            {
                where = where && SZCourtColumns.pCourtUseStatistics.SiteCol.Like(siteCol+"%");
            }

            if (!string.IsNullOrEmpty(deptName))
            {
                where = where && SZCourtColumns.pCourtUseStatistics.DeptName == deptName;
            }

            if (!string.IsNullOrEmpty(User))
            {
                where = where && SZCourtColumns.pCourtUseStatistics.AddUser.Like(User + "%") ;
            }

            if (beginDate.Year > DateTime.MinValue.Year)
            {
                where = where && SZCourtColumns.pCourtUseStatistics.AddDate >= beginDate;
            }
            if (endDate.Year > DateTime.MinValue.Year)
            {
                where = where && SZCourtColumns.pCourtUseStatistics.AddDate <= endDate;
            }

            result.ResultList = NBLData
                .Select(SZCourtColumns.pCourtUseStatistics)
                .Where(where)
                .SetSelectRange(condition.PageSize, condition.PageSize * (condition.PageIndex - 1), SZCourtColumns.pCourtUseStatistics.CUSID)
                .OrderBy(SZCourtColumns.pCourtUseStatistics.AddDate.Desc)
                .ToList<pCourtUseStatistics>();

            int total = -1;
            if (condition.TotalCount == -1)
            {
                total = GetTotalRecord(SZCourtColumns.pCourtUseStatistics, SZCourtColumns.pCourtUseStatistics.CUSID, where);
            }
            result.PageIndex = condition.PageIndex;
            result.PageSize = condition.PageSize;
            result.TotalCount = total;
            return result;
        }
    }
}
